package org.microser.gataway.zuul.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;

/**
 * 自定义的zuul过滤器，原因：因为自己实现了 路由过滤，什么路由给指定的filter器过滤
 *
 * @author liujiamiao
 * @email 2544296058@qq.com
 * @date 2020-11-24 11:01
 */
@Slf4j
public abstract class DefinedZuulFilter extends ZuulFilter {

    /** 前置过滤 */
    public final static String FILTERTYPE_PRE = "pre";
    public final static String FILTERTYPE_ROUTE = "route";
    /**
     * 中段过滤
     */
    public final static String FILTERTYPE_POST = "post";
    public final static String FILTERTYPE_ERROR = "error";

    //是否执行这个过滤器，默认不执行
    private boolean flag = false;

    public void setFlag(boolean flag){
        this.flag = flag;
    }
    public boolean getFlag(){
        return flag;
    }

    @Override
    public Object run() throws ZuulException {
        return null;
    }

//    public abstract Object init() throws ZuulException;

    @Override
    public int filterOrder() {
        return 1;// 优先级为0，数字越大，优先级越低
    }

    @Override
    public boolean shouldFilter() {
        boolean flag = this.getFlag();
        this.setFlag(false);
        return flag;// 是否执行该过滤器，此处为true，说明需要过滤
    }
}
